﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Game_Engine
{
    public static class ScreenManager
    {
        private static GraphicsDeviceManager graphics;

        public static GraphicsDevice GraphicsDevice
        {
            get { return graphics.GraphicsDevice; }
        }

        public static void Initialize(GraphicsDeviceManager graphics)
        {
            ScreenManager.graphics = graphics;
        }

        public static Viewport DefaultViewport
        {
            get { return new Viewport(0, 0, Width, Height); }
        }

        public static int Width
        {
            get { return graphics.PreferredBackBufferWidth; }
            set
            {
                graphics.PreferredBackBufferWidth = value;
                graphics.ApplyChanges();
            }
        }

        public static int Height
        {
            get { return graphics.PreferredBackBufferHeight; }
            set
            {
                graphics.PreferredBackBufferHeight = value;
                graphics.ApplyChanges();
            }
        }

        public static bool IsFullScreen
        {
            get { return graphics.IsFullScreen; }
            set
            {
                graphics.IsFullScreen = value;
                if (IsFullScreen)
                {
                    Width = graphics.GraphicsDevice.DisplayMode.Width;
                    Height = graphics.GraphicsDevice.DisplayMode.Height;
                }
                graphics.ApplyChanges();
            }
        }

        public static void Setup(uint width = 0, uint height = 0)
        {
            Setup(IsFullScreen, width, height);
        }

        public static void Setup(bool fullScreen, uint width = 0, uint height = 0)
        {
            if (width > 0)
                graphics.PreferredBackBufferWidth = (int)width;
            if (height > 0)
                graphics.PreferredBackBufferHeight = (int)height;
            graphics.IsFullScreen = fullScreen;
            graphics.ApplyChanges();
        }
    }
}
